﻿Public Class FormFlbInfoList
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim objFLBinfo As New clsFlbInfo
    Dim objLog As New clsLog
    Private Sub FormFlbInfoList_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        setDgvData()
    End Sub

    Public Sub setDgvData()
        If String.IsNullOrEmpty(txt_dl_no.Text.Trim()) = False Then
            Dim dt As DataTable = objFLBinfo.getFlbInfoByDlNo(txt_dl_no.Text.Trim())
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dt
        Else
            MsgBox("请输入法兰板吊篮号", vbYes, "提示")
        End If
    End Sub
    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            txt_piece_num.Value = dgv.SelectedRows(0).Cells("piece_num").Value.ToString()
            txt_used_piece_num.Value = dgv.SelectedRows(0).Cells("used_piece_num").Value.ToString()
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If dgv.SelectedRows.Count > 0 Then
            If txt_used_piece_num.Value >= 0 Then
                If txt_used_piece_num.Value <= txt_piece_num.Value Then
                    Dim sys_id As String = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
                    Dim rtn As Integer = objFLBinfo.saveUpdate(txt_piece_num.Text.Trim(), txt_used_piece_num.Text.Trim(), sys_id)
                    If rtn <> -2 Then
                        MsgBox("保存成功！", vbYes, "提示")
                        objLog.insert("法兰板吊篮", "法兰板完成数量", "法兰板吊篮sys_id：" & sys_id & "，完成数量改为：" & txt_used_piece_num.Text.Trim())
                        setDgvData()
                    Else
                        MsgBox("保存失败！", vbYes, "提示")
                    End If
                Else
                    MsgBox("已使用数量，不能大于装配数量", vbYes, "提示")
                End If
            Else
                MsgBox("已使用数量，需 ≥ 0", vbYes, "提示")
            End If
        Else
            MsgBox("请选择需要修改的吊篮！", vbYes, "提示")
        End If
    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        If dgv.SelectedRows.Count > 0 Then
            If dgv.SelectedRows(0).Cells("Col_status").Value.ToString().Equals("0") Then
                If MsgBox("确认删除吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
                    Dim dl_no As String = dgv.SelectedRows(0).Cells("dl_no").Value.ToString()
                    Dim rtn As Integer = objFLBinfo.saveDelete(dl_no, sys_id)
                    If rtn <> -2 Then
                        MsgBox("删除成功！", vbYes, "提示")
                        objLog.insert("法兰板吊篮", "法兰板吊篮删除", "法兰板吊篮sys_id：" & sys_id & "，删除了")
                        setDgvData()
                    Else
                        MsgBox("删除失败！", vbYes, "提示")
                    End If
                End If
            Else
                MsgBox("当前吊篮信息已使用，无法进行删除！", vbYes, "提示")
            End If
        Else
            MsgBox("请选择需要删除的吊篮！", vbYes, "提示")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_used_piece_num.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

End Class